package com.leilei.serviceProject.domain.strategy.model.entity;

import com.leilei.serviceProject.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @author yanglei
 * @description
 * @create 2024/10/21 15:00
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {
    /**
     * 抽奖策略ID
     */
    private Long strategyId;
    /**
     * 抽奖策略描述
     */
    private String strategyDesc;
    /**
     * 规则模型，rule配置的模型同步到此表，便于使用
     */
    private String ruleModels;

    public String[] ruleModels() {
        if (StringUtils.isEmpty(ruleModels)) {
            return null;
        }
        return ruleModels.split(Constants.SPLIT);
    }

    public String getRuleWeight() {
        String[] ruleModels = this.ruleModels();
        if (null == ruleModels) {
            return null;
        }
        for (String ruleMode : ruleModels) {
            if ("rule_weight".equals(ruleMode)) {
                return ruleMode;
            }
        }
        return null;
    }
}
